package com.leyou.controller;

import com.leyou.pojo.Spec_group;
import com.leyou.pojo.Spec_param;
import com.leyou.service.Spec_groupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("spec")
public class SpecController {
    @Autowired
    private Spec_groupService spec_groupService;

    //通过第三级分类查询规格组
    @RequestMapping("groups/{cid}")
    public List<Spec_group> groups(@PathVariable("cid") Integer cid){
        List<Spec_group> list=spec_groupService.groups(cid);
        return list;
    }
    @PostMapping("group")
    public void add(@RequestBody Spec_group spec_group ){
       spec_groupService.add(spec_group);
    }
    @PutMapping("group")
    public void  update(@RequestBody Spec_group spec_group){
        spec_groupService.update(spec_group);
    }
    @RequestMapping("group/{id}")
    public void  delete(@PathVariable("id") Integer id){
       spec_groupService.delete(id);
    }
    @RequestMapping("params")
    public List<Spec_param> params(@RequestParam("gid") Integer gid){
        List<Spec_param>  list=spec_groupService.params(gid);
        return list;
    }
    @DeleteMapping("param/{id}")
    public void deleteParam(@PathVariable("id")Integer id){
        spec_groupService.deleteParam(id);
    }
    @PostMapping("param")
    public void addParam(@RequestBody Spec_param spec_param){
        spec_groupService.addParam(spec_param);
    }
    @PutMapping("param")
    public void updateParam(@RequestBody Spec_param spec_param){
        spec_groupService.updateParam(spec_param);
    }

    @RequestMapping("getparams")
    public List<Spec_param> getparams(@RequestParam("cid")Integer cid){
        List<Spec_param>list= spec_groupService.getParams(cid);
        return list;
     }

      //查询规格参数并且为可搜索的
    @RequestMapping("getparamsq")
    public List<Spec_param> getparamsq(@RequestParam("cid")Integer cid){
        List<Spec_param>list= spec_groupService.getParamsq(cid);
        return list;
    }

    //查询规格参数并且为通用规格
    @RequestMapping("fingParamByCidAndGeneric")
    public List<Spec_param> fingParamByCidAndGeneric(@RequestParam("id") Integer cid){
        List<Spec_param>list=spec_groupService.fingParamByCidAndGeneric(cid);
        return list;
    }


}
